<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>发布租车位信息</title>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

  <style type="text/css">
  	#infoDiv{
  		margin-top: 20px;
  		width: 900px;
  	}
  	#publishBt{
	margin-left: 160px;
	width: 50px;	  	
  	}
  	#chooseCarPort{
  		width: 200px;
  		height: 40px;
  	}
    .form-control{
        width: 200px;
    }
    label{
        float: right;
        margin-top: 5px;
    }
    .col-sm-4{
        padding: 0px;
        margin-top: 30px;
        width: 240px;
    }
  </style>
</head>
<body>
<div id="infoDiv">
	<form action="publishInfo.do" method="post" class="form-horizontal" onsubmit="return check()">
	<input type="hidden" id="ladyID" value="${sessionScope.myLandLady.ladyID }">
    <div class="row">
        <div class="col-xs-6 col-sm-4">
            <label>选择待租车位：</label>
        </div>
        <div class="col-xs-6 col-sm-4">
            <select id="chooseCarPort" name="carPortID"  class="form-control" onfocus="cleanChoose()"></select>
        </div>
         <div class="col-xs-6 col-sm-4">
            <label style="float:left;"> <span id="notice"></span></label>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-6 col-sm-4">
            <label>租借开始时间：</label>
        </div>
        <div class="input-group date form_datetime col-xs-6 col-sm-4" data-date="" data-date-format="yyyy-mm-dd hh:ii" data-link-field="startTime" data-link-format="yyyy-mm-dd hh:ii">
            <input id="startTime"  class="form-control" type="text" name="startTime" value=""  onfocus="cleanStartTimeMessage()">
            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
            <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
           
        </div>
        <div class="col-xs-6 col-sm-4">
            <label style="float:left;"><span id="checkStartTime"></span></label>
        </div>
            <input type="hidden" id="startTime" name="startTime" value="" />
    </div>
    <div class="row">
        <div class="col-xs-6 col-sm-4">
            <label>租借结束时间：</label>
        </div>
        <div class="input-group date form_datetime col-xs-6 col-sm-4" data-date="" data-date-format="yyyy-mm-dd hh:ii" data-link-field="endTime" data-link-format="yyyy-mm-dd hh:ii">
            <input id="endTime"  class="form-control" type="text" name="endTime"value=""  onfocus="cleanEndTimeMessage()">
            <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
            <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
            
        </div>
        <div class="col-xs-6 col-sm-4">
            <label style="float:left;"> <span id="checkEndTime"></span></label>
        </div>
            <input type="hidden" id="endTime" name="endTime" value="" />
    </div>
     <div class="row">
        <div class="col-xs-6 col-sm-4">
            <label>出租价格：</label>
        </div>
        <div class="col-xs-6 col-sm-4">
            <input type="text" class="form-control" id="rentPrice" name="price" onblur="checkPrice()" onfocus="cleanPriceMessage()" onblur="checkPrice()"></div>
        <div class="col-xs-6 col-sm-4">
            <label style="float:left;"><span id="priceMessage"></span></label>
        </div>
    </div>
  	<div class="form-group" style="margin-left:300px;margin-top:80px;">
   	 	<label for="publishBt" class="col-sm-2 control-label"><input type="submit" id="publishBt" name="publishBt"  class="form-control btn btn-primary" value="发布"></label>
    	
  	</div>
	</form>
</div>	
</body>

<script type="text/javascript">
$(function(){
	init();
})
function init(){
	chickAllCarPort();
	getAllCarPort();
}
function chickAllCarPort(){
	$.ajax({
		url:"checkAllPort.do",
		type:"post",
		async:true,
		success:function(){

		}
	})
}
function getAllCarPort(){
	var option;
	var id=$("#ladyID").val();
	$.ajax({
		url:"getAllCarPort.do",
		type:"post",
		async:true,
		data:{"id":id},
		success:function(msg){
			
			for (var i = 0; i < msg.length; i++) {
				option+="<option value='"+msg[i].carportID+"'>"+msg[i].carportAddress+msg[i].carNO+"</option>";
			}
			$("#chooseCarPort").append(option);
		}
	})
	
	
}
$('.form_datetime').datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
	autoclose: 1,
	todayHighlight: 1,
	startView: 2,
	forceParse: 0,
    showMeridian: 1
});
$('.pactEndTime').datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
	autoclose: 1,
	todayHighlight: 1,
	startView: 2, 
	forceParse: 0,
    showMeridian: 1
});
function check() {
	var flag = checkPrice()&&checkTime()&&checkChoose();
	return flag;
}

function checkPrice() {
	var rentPrice = document.getElementById("rentPrice").value;
	var priceMessage = document.getElementById("priceMessage");
	var eReg = /^\+?[1-9][0-9]*$/;
	if (rentPrice.length == 0) {
		priceMessage.innerHTML = "出售价格不能为空";
		return false;
	} else if (!eReg.test(rentPrice)) {
		priceMessage.innerHTML = "出售价格必须为非零的正整数"
			return false;
	} else {
		return true;
	}
}
function checkTime(){
	var pactEndTime = $("#endTime").val();
	var pactStartTime = $("#startTime").val();
	if(pactEndTime=="" || pactStartTime==""){
		$("#checkStartTime").html("你还未选择时间!")
		return false;
	}else{
			var endTime = pactEndTime.split(" ")[0].split("-");
			var startTime =	pactStartTime .split(" ")[0].split("-");
			var endDate = new Date();
			endDate.setFullYear(endTime[0],endTime[1],endTime[2]);
			var startDate = new Date();
			startDate.setFullYear(startTime[0],startTime[1],startTime[2]);
			var timestamp = Date.parse(new Date());
			if(endDate<startDate || endDate==startDate ){
				$("#checkEndTime").html("结束日期不能小于或等于开始日期!")
				$("#endTime").val("");
				return false;
			}else if(Date.parse(pactStartTime)<timestamp){
				$("#checkStartTime").html("开始日期必须大于当前日期！")
				$("#startTime").val("");
				$("#endTime").val("");
				return false;
			}else{
				return true;
		}
	}
}
//清除内容

function cleanPriceMessage(){
	var priceMessage = document.getElementById("priceMessage");
	priceMessage.innerHTML = "";
}
function checkChoose(){
	if($("#chooseCarPort option:selected").val()==null){
		$("#notice").html("请选择车位！")
		return false;
	}else{
		return true;
	}
}
function cleanEndTimeMessage(){
	$("#checkEndTime").html("");
}
function cleanStartTimeMessage(){
	$("#checkStartTime").html("");
}
function cleanChoose(){
	$("#notice").html("");
}
</script>
</html>